#ifndef _MAP_MANAGER_H_
#define _MAP_MANAGER_H_

#include <map>

#include "maptile.h"
#include "../common/singleton.h"

struct TileOnLine
{
    int start;
    int mapid;
    int end;
};
typedef std::vector<TileOnLine> LineData;
typedef std::vector<LineData> MapLines;
typedef std::map<int, CMapTile*> MapTileMap;
class CMapLoader;

class CMapManager:public CSingleton<CMapManager>
{
	IMPLEMENT_SINGLETON(CMapManager);
    friend class CMapLoader;
public:
	bool Update( uint32 delta );
	CMapTile* CreateMapTile(int id);
    bool AddMapTile( CMapTile *tile );
	CMapTile* FindMapTile(int id);
    bool RemoveMapTile(int id);
    void AddTileLine(uint32 line, int start, int mapid, int end );
    void SaveMapLineInfo( );    
    CMapTile* GetClickedTile( POINT & p );

    void SaveMapData();
    bool LoadMapData();
    void RenderMap();
    void ComputeAdjacency();
    void ComputeMapRegion();

    void ConvertToScaledCoord( IRect &maprect ); 
    void ConvertToOriginalCoord( IRect &rect );
private:
	std::map<int, CMapTile*> m_maps;
    MapLines m_lines;
};
#define MapMgr CMapManager::Instance()
#endif